import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '@/layout'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    meta: {
      icon: 'el-icon-loading',
      title: '首页'
    },
    children: [
      {
        path: 'dashboard',
        component: () => import('@/pages/dashboard/index'),
        name: '首页',
        meta: {
          title: '首页',
          affix: true
        }
      }

    ]

  },
  {
    path: '/secondary-card',
    component: Layout,
    redirect: '/secondary-card/secondary-card',
    meta: {
      title: '次卡管理',
      icon: 'el-icon-medal-1'
    },
    children: [
      {
        path: 'secondary-card',
        component: () => import('@/views/secondary-card/secondary-card.vue'),
        name: 'secondary-card',
        meta: {
          title: '次卡管理'
        }
      }

    ]
  },
  {
    path: '/chargeable-item',
    component: Layout,
    redirect: '/chargeable-item/chargeable-item',
    meta: {
      title: '收费项目管理',
      icon: 'el-icon-coin'
    },
    children: [
      {
        path: 'chargeable-item',
        component: () => import('@/views/chargeable-item/chargeable-item.vue'),
        name: 'chargeable-item',
        meta: {
          title: '收费项目管理'
        }
      }
    ]
  },
  {
    path: '/location',
    component: Layout,
    redirect: '/location/location',
    meta: {
      title: '场所管理',
      icon: 'el-icon-office-building'
    },
    children: [
      {
        path: 'location',
        component: () => import('@/views/location/location.vue'),
        name: 'location',
        meta: {
          title: '场所管理'
        }
      }
    ]
  },
  {
    path: '/course',
    component: Layout,
    redirect: '/course/course',
    meta: {
      title: '课程管理',
      icon: 'el-icon-data-analysis'
    },
    children: [
      {
        path: 'course',
        component: () => import('@/views/course/course.vue'),
        name: 'course',
        meta: {
          title: '课程管理'
        }
      }
    ]
  },
  {
    path: '/admission-record',
    component: Layout,
    redirect: '/admission-record/admission-record',
    meta: {
      title: '入场记录管理',
      icon: 'el-icon-tickets'
    },
    children: [
      {
        path: 'admission-record',
        component: () => import('@/views/admission-record/admission-record.vue'),
        name: 'admission-record',
        meta: {
          title: '入场记录管理'
        }
      }
    ]
  },
  {
    path: '/entrance-venues',
    component: Layout,
    redirect: '/entrance-venue/entrance-venue',
    meta: {
      title: '场馆入口管理',
      icon: 'el-icon-school'
    },
    children: [
      {
        path: 'entrance-venue',
        component: () => import('@/views/entrance-venue/entrance-venue.vue'),
        name: 'entrance-venue',
        meta: {
          title: '场馆入口管理'
        }
      }
    ]
  },
  {
    path: '/help',
    component: Layout,
    redirect: '/help/help',
    meta: {
      icon: 'el-icon-thumb',
      title: '帮助管理'
    },
    children: [
      {
        path: 'help',
        component: () => import('@/views/help/help.vue'),
        name: 'help',
        meta: {
          title: '帮助管理'
        }
      }
    ]
  },
  {
    path: '/activity',
    component: Layout,
    redirect: '/activity/activity',
    meta: {
      title: '活动管理',
      icon: 'el-icon-chat-dot-round'
    },
    children: [
      {
        path: 'activity',
        component: () => import('@/views/activity/activity.vue'),
        name: 'activity',
        meta: {
          title: '活动管理'
        }
      }
    ]
  },
  {
    path: '/feed-back',
    component: Layout,
    redirect: '/feed-back/feed-back',
    meta: {
      title: '意见反馈管理',
      icon: 'el-icon-wallet'
    },
    children: [
      {
        path: 'feed-back',
        component: () => import('@/views/feed-back/feed-back.vue'),
        name: 'feed-back',
        meta: {
          title: '意见反馈管理'
        }
      }
    ]
  },
  {
    path: '/single-entry',
    component: Layout,
    redirect: '/single-entry/single-entry',
    meta: {
      title: '单次入场管理',
      icon: 'el-icon-medal'
    },
    children: [
      {
        path: 'single-entry',
        component: () => import('@/views/single-entry/single-entry.vue'),
        name: 'single-entry',
        meta: {
          title: '单次入场管理'
        }
      }
    ]
  },
  {
    path: '/training-card',
    component: Layout,
    redirect: '/training-card/training-card',
    meta: {
      title: '培训卡管理 ',
      icon: 'el-icon-money'
    },
    children: [
      {
        path: 'training-card',
        component: () => import('@/views/training-card/training-card.vue'),
        name: 'training-card',
        meta: {
          title: '培训卡管理 '
        }
      }
    ]
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () =>
        import('@/pages/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () =>
      import('@/pages/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () =>
      import('@/pages/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () =>
      import('@/pages/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () =>
      import('@/pages/error-page/401'),
    hidden: true
  },

  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [{
      path: 'index',
      component: () =>
        import('@/pages/profile/index'),
      name: 'Profile',
      meta: { title: 'profile', icon: 'user', noCache: true }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  // {
  //     path: '/i18n',
  //     component: Layout,
  //     children: [{
  //         path: 'index',
  //         component: () =>
  //             import ('@/pages/i18n-demo/index'),
  //         name: 'I18n',
  //         meta: { title: 'i18n', icon: 'international' }
  //     }]
  // },

  {
    path: '/operate',
    component: Layout,
    redirect: '/operate/swiper',
    meta: {
      title: '运营管理',
      icon: 'el-icon-c-scale-to-original'
    },
    children: [
      {
        path: 'swiper',
        component: () => import('@/pages/operate/swiper'),
        name: 'swiper',
        meta: { title: '轮播图管理' }
      },
      {
        path: 'share-images',
        component: () =>
          import('@/pages/operate/share-images'),
        name: 'share-images',
        meta: { title: '分享图列表' }
      },
      {
        path: 'video',
        component: () =>
          import('@/pages/operate/video'),
        name: 'video',
        meta: { title: '视频管理' }
      }
    ]
  },

  {
    path: '/jurisdiction',
    component: Layout,
    redirect: '/jurisdiction/role',
    meta: {
      title: '权限管理',
      icon: 'el-icon-lock'
    },
    children: [
      {
        path: 'role',
        component: () =>
          import('@/pages/jurisdiction/role'),
        name: 'role',
        meta: { title: '角色管理' }
      },
      {
        path: 'menu',
        component: () =>
          import('@/pages/jurisdiction/menu'),
        name: 'menu',
        meta: { title: '菜单管理' }
      },
      {
        path: 'admin_user',
        component: () =>
          import('@/pages/admin/admin_user'),
        name: 'admin_user',
        meta: { title: '管理员列表' }
      }

    ]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/system/nav-params',
    meta: {
      title: '系统管理',
      icon: 'el-icon-setting'
    },
    children: [
      {
        path: 'params-setting',
        component: () =>
          import('@/pages/admin/params-setting'),
        name: '参数设置',
        meta: { title: '参数设置' }
      },

      {
        path: 'wxpage',
        component: () =>
          import('@/pages/admin/wxpage'),
        name: 'wxpage',
        meta: { title: '页面设置' }
      }
    ]
  }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
